package com.yanggu.mapreduce.manyjob;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2020/2/8 21:03
 * @description:
 */
public class TwoJobReducer extends Reducer<Text, Text, Text, Text> {

    private Text v = new Text();

    @Override
    protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        //atguigu--a.txt	3

        StringBuilder sb = new StringBuilder();
        //1. 循环遍历，拼接字符串
        for (Text value : values) {
            sb.append(value.toString().replace("\t", "-->")).append("\t");
        }

        //2. 写出
        v.set(sb.toString());
        context.write(key, v);
    }
}
